package com.xit.hitmouse.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.xit.hitmouse.Bean.PropsBean;
import com.xit.hitmouse.R;

import java.util.List;

/**
 * @author 厦工 友敏612
 * @Date 2023/11/24
 */
public class PropsAdapter extends RecyclerView.Adapter<PropsAdapter.PropsViewHolder> {

    private List<PropsBean> propsList; // 假设 PropsModel 包含了图片、名称和描述等属性

    // 构造方法
    public PropsAdapter(List<PropsBean> propsList) {
        this.propsList = propsList;
    }

    // 创建 ViewHolder
    @NonNull
    @Override
    public PropsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.shop_props_item, parent, false);
        return new PropsViewHolder(view);
    }

    // 绑定数据到 ViewHolder
    @Override
    public void onBindViewHolder(@NonNull PropsViewHolder holder, int position) {
        PropsBean props = propsList.get(position);
        holder.bindData(props);
    }

    // 返回项的数量
    @Override
    public int getItemCount() {
        return propsList.size();
    }

    // ViewHolder 类
    public static class PropsViewHolder extends RecyclerView.ViewHolder {
        ImageView propImage;
        TextView propName;
        TextView propDescription;

        public PropsViewHolder(View itemView) {
            super(itemView);
            propImage = itemView.findViewById(R.id.item_image);
            propName = itemView.findViewById(R.id.item_name);
            propDescription = itemView.findViewById(R.id.item_description);
        }

        public void bindData(PropsBean props) {
            propImage.setImageResource(props.getImg());
            propName.setText(props.getName());
            propDescription.setText(props.getDescription());
        }
    }

}